export const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}


export const getUrlParams = () => {
  let url = location.href
  let obj = {}
  let params = url.slice(url.indexOf('?') + 1, url.length).split('&')
  params.forEach((item) => {
    obj[item.split('=')[0]] = item.split('=')[1]
  })
  return obj
}


export const getRandom = () => {
  const Letter = new Array('a','b','c','d','e','f','g','h','i','g','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
  const random1 = Math.round(Math.random()*26);
  const random2 = Math.round(Math.random()*26);
  return 'dh' + Letter[random1] + Letter[random2] + (Math.floor(Math.random()*8999 +1000));
}